using System.Collections;
using UnityEngine;
using ZSW.Framework;

public static class CoroutineRunner
{
    private static MonoBehaviour m_runner;

    public static void Initialize(MonoBehaviour runnerInstance)
    {
        m_runner = runnerInstance;
    }

    public static Coroutine StartCoroutine(IEnumerator routine)
    {
        if (m_runner == null)
        {
            m_runner = ZSWF_CoroutineRunner.Instance;
        }
        return m_runner.StartCoroutine(routine);
    }

    public static void StopCoroutine(IEnumerator routine)
    {
        if (m_runner != null)
            m_runner.StopCoroutine(routine);
    }

    public static void StopCoroutine(Coroutine routine)
    {
        if (m_runner != null)
            m_runner.StopCoroutine(routine);
    }
}

public class ZSWF_CoroutineRunner : ZSWF_Singleton<ZSWF_CoroutineRunner>
{
    protected override void Awake()
    {
        base.Awake();
        CoroutineRunner.Initialize(this);
    }

    private void OnDestroy()
    {
        StopAllCoroutines();
    }
}
